/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servidor;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.swing.text.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;


/**
 *
 * @author lab_a112
 */

public class acciones 
{
    public String traeracciones(){

        Vector vec= new Vector();
        String result= "<!DOCTYPE StockQuotes SYSTEM \"docDtd.dtd\">";
        result += "<StockQuotes>";
        String result1= "";


        vec.add("pas");
        vec.add("mac");
        vec.add("pg");
        vec.add("gt");
        vec.add("dpz");
        vec.add("msft");
        vec.add("aapl");
        /*vec.add("mtu");
        vec.add("orcl");
        vec.add("IBM");
        vec.add("ANF");
        vec.add("ADS.DE");
        vec.add("NIKE");
        vec.add("HPQ");
        vec.add("NOK");*/

    try { // Call Web Service Operation
            net.webservicex.StockQuote service = new net.webservicex.StockQuote();
            net.webservicex.StockQuoteSoap port = service.getStockQuoteSoap();
            // TODO initialize WS operation arguments here
            for(int i = 0; i< vec.size();i++)
            {
                String symbol = vec.get(i).toString();
                result1 = port.getQuote(symbol);
                result += result1.substring(13, result1.length() - 14);
            }
            //System.out.println("Result = "+ result);
            result += "</StockQuotes>";
            return(result);
     } catch (Exception ex) {
            return null;
        }

   }


public void grabarArchivo(byte[] result) {

    File fichero = new File("C:/Users/Anya/Documents/NetBeansProjects/Servidor/acciones.xml");
    
    if(fichero.exists())
    {
        fichero.delete();
    }
    try 
    {
        FileOutputStream salida = new FileOutputStream("C:/Users/Anya/Documents/NetBeansProjects/Servidor/acciones.xml");
        salida.write(result);
        salida.close();
    } catch (Exception e) {
       System.out.println("Error de escritura, archivo de errores");
    }
}



}
